package eu.szemraj.utils.time {
   import flash.utils.getTimer;   

   /**
    *  Quest Agency
    *  www: http://www.questagency.pl
    *  email: info@questagency.pl
    *  @author Rafal Szemraj ( rafal@questagency.pl )
    */
   public class StopWatch {

      protected var _startTime:int;
      protected var _elapsedTime:int;
      protected var _stopped:Boolean = true; 

      public function StopWatch() {
      }

      public function start():void {
      	
         this._elapsedTime = 0;
         this._startTime = timerValue;
         this._stopped = false;
      }

      public function stop():void {
			
         this._elapsedTime = this.time;
         this._startTime = 0;
         this._stopped = true;
      }

      public function resume():void {
         if (this._stopped)
				this._startTime = timerValue;
      }

      public function get time():int {
         return (this._startTime != 0) ? timerValue - _startTime + _elapsedTime : _elapsedTime;
      }

      protected function get timerValue():int {
      	
         return getTimer( );
      }
   }
}
